package com.smartscreen.attendancemanage.controller;

import com.smartscreen.attendancemanage.dto.ApprovalLeaveRequest;
import com.smartscreen.attendancemanage.dto.CreateLeaveApplicationRequest;
import com.smartscreen.attendancemanage.entity.LeaveApplication;
import com.smartscreen.attendancemanage.service.LeaveApplicationService;
import com.smartscreen.common.response.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/attendance/leave")
public class LeaveController {
    
    @Autowired
    private LeaveApplicationService leaveApplicationService;
    
    @PostMapping("/applications")
    public ApiResponse<Map<String, String>> createLeaveApplication(
            @RequestBody CreateLeaveApplicationRequest request) {
        String applicationId = leaveApplicationService.createLeaveApplication(request);
        Map<String, String> data = new HashMap<>();
        data.put("applicationId", applicationId);
        return ApiResponse.created("请假申请提交成功，等待审批", data);
    }
    
    @GetMapping("/applications/pending")
    public ApiResponse<List<LeaveApplication>> getPendingApplications() {
        List<LeaveApplication> applications = leaveApplicationService.getPendingApplications();
        return ApiResponse.success(applications);
    }
    
    @PostMapping("/applications/{applicationId}/approval")
    public ApiResponse<Void> approveLeaveApplication(
            @PathVariable String applicationId,
            @RequestBody ApprovalLeaveRequest request) {
        leaveApplicationService.approveLeaveApplication(applicationId, request);
        return new ApiResponse<>(200, "审批操作成功");
    }
}